package com.haq.housesystem.ctrl;

import com.github.pagehelper.PageInfo;
import com.haq.housesystem.bean.HousesOrient;
import com.haq.housesystem.bean.HousesType;
import com.haq.housesystem.service.HousesOrientService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;



@RestController
@RequestMapping("/housesOrient")
public class HousesOrientCtrl {

    @Autowired
    HousesOrientService housesOrientService;

    @RequestMapping("insert")
    public Map insert(HousesOrient housesOrient){
        housesOrientService.insert(housesOrient);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("/update")
    public Map update(HousesOrient housesOrient){
        housesOrientService.update(housesOrient);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("/delete")
    public Map delete(int orientId){
        housesOrientService.delete(orientId);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("deleteByIds")
    public Map deleteByIds(int [] orientIds){
        housesOrientService.deleteByIds(orientIds);
        Map map=new HashMap();
        map.put("state", "success");
        return map;
    }
    @RequestMapping("selectAll")
    public Map selectAll(){

        List<HousesOrient> housesOrientList=housesOrientService.selectAll();
        Map map=new HashMap();
        map.put("state","success");
        map.put("housesorientlist",housesOrientList);
        return map;
    }
    @RequestMapping("selectByName")
    public Map selectByName(String orientName){

        List<HousesOrient> housesOrientList=housesOrientService.selectByName(orientName);
        Map map=new HashMap();
        map.put("state","success");
        map.put("housesorientlist",housesOrientList);
        return map;
    }
    @RequestMapping("selectById")
    public Map selectById(int orientId){

        HousesOrient housesOrient=housesOrientService.selectById(orientId);
        Map map=new HashMap();
        map.put("state","success");
        map.put("housesorientlist",housesOrient);
        return map;
    }

    //分页查询全部
    @RequestMapping("/selectAllByPageInfo")
    public Map selectAllByPageInfo(@RequestParam(required=false,defaultValue="1")int curPage, @RequestParam(required=false,defaultValue="3")int size) {
        PageInfo<HousesOrient> pageInfo = housesOrientService.selectAllByPageInfo(curPage, size);

        Map map=new HashMap();
        map.put("state", "success");
        //list数据
        map.put("housesorientlist", pageInfo.getList());
        //总记录数
        map.put("total", pageInfo.getTotal());
        return map;
    }
    @RequestMapping("/selectByNameByPageInfo")
    public Map selectAllByNameStatePageInfo(@RequestParam(required=false,defaultValue="1")int curPage,@RequestParam(required=false,defaultValue="3")int size,String orientName) {
        PageInfo<HousesOrient> pageInfo = housesOrientService.selectByNameByPageInfo(curPage, size, orientName);

        Map map=new HashMap();
        map.put("state", "success");
        //list数据
        map.put("housesorientlist", pageInfo.getList());
        //总记录数
        map.put("total", pageInfo.getTotal());
        return map;
    }
}
